package com.ashin.spring.jms.comusure.lstr;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import javax.jms.TextMessage;

public class ConsumerMessageListener implements MessageListener {

    @Override
    public void onMessage(Message message) {
        try {
            System.out.println("获取消息类型:" + message.getJMSType());
        } catch (JMSException e1) {
            e1.printStackTrace();
        }

        if (message instanceof TextMessage) {
            TextMessage tm = (TextMessage) message;
            try {
                System.out.println("ConsumerMessageListener收到了文本消息：\t" + tm.getText());
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }

        if (message instanceof ObjectMessage) {
            ObjectMessage tm = (ObjectMessage) message;
            try {
                System.out.println("ConsumerMessageListener收到了对象消息：\t" + tm.getObject());

            } catch (JMSException e) {
                e.printStackTrace();
            }

            int i = 1 / 0;
            System.out.println(i);
        }
    }

}
